#ifndef CMAP_H
#define CMAP_H

#include <stdio.h>

/**
 * @todo write docs
 */

typedef struct CMAP CMAP;

#ifdef __cplusplus
extern "C" {
#endif

    /* new an instance of HashTable */
    CMAP* cmap_new();

    /*
    delete an instance of CMAP,
    all values are removed auotmatically.
    */
    void cmap_delete(CMAP* ht);

    /*
    add or update a value to ht,
    free_value(if not NULL) is called automatically when the value is removed.
    return 0 if success, -1 if error occurred.
    */
    int cmap_put2(CMAP* ht, void* key, size_t keylen, void* value, void(*free_value)(void*));

    /* get a value indexed by key, return NULL if not found. */
    void* cmap_get(CMAP* ht, void* key, size_t keylen);

    /* remove a value indexed by key */
    void cmap_rm(CMAP* ht, void* key, size_t keylen);

    void cmap_foreach(CMAP* ht, void (*callback)(void *, size_t, void *, void *), void *userparm);
#ifdef __cplusplus
}
#endif

#endif // CMAP_H
